﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Migraine.BLL
{
    class NhomTrieuChungBUO
    {
        BenhDataContext context = new BenhDataContext();
        public tbl_NhomTC GetSingle(int id)
        {
            return context.tbl_NhomTCs.Where(n => n.idNhomTC == Convert.ToString(id)).ToList<tbl_NhomTC>().FirstOrDefault();
        }

        public string GetTenNhomTC(int id)
        {
            return context.tbl_NhomTCs.Where(n => n.idNhomTC == Convert.ToString(id)).ToList<tbl_NhomTC>().FirstOrDefault().Ten;
        }

        public string GetIDFromTenNhomTC(string nstring)
        {
            return context.tbl_NhomTCs.Where(n => n.Ten == nstring).ToList<tbl_NhomTC>().FirstOrDefault().idNhomTC;
        }

        public List<tbl_NhomTC> GetAll()
        {
            return context.tbl_NhomTCs.OrderByDescending(n => n.idNhomTC).ToList<tbl_NhomTC>();
        }
        public bool Insert(tbl_NhomTC obj)
        {
            try
            {
                context.tbl_NhomTCs.InsertOnSubmit(obj);
                context.SubmitChanges();
                return true;
            }
            catch (Exception)
            {

                return false;
            }
        }
        public bool Update(int id, tbl_NhomTC obj)
        {
            try
            {
                tbl_NhomTC bn = context.tbl_NhomTCs.Where(n => n.idNhomTC == Convert.ToString(id)).ToList<tbl_NhomTC>().FirstOrDefault();
                bn = obj;
                context.SubmitChanges();
                return true;

            }
            catch (Exception)
            {

                return false;
            }
        }
        public bool Delete(int id)
        {
            try
            {
                tbl_NhomTC obj = context.tbl_NhomTCs.Where(n => n.idNhomTC == Convert.ToString(id)).First<tbl_NhomTC>();
                if (obj != null)
                {
                    context.tbl_NhomTCs.DeleteOnSubmit(obj);
                    context.SubmitChanges();
                    return true;
                }
                else
                {
                    return false;
                }
            }
            catch (Exception)
            {

                throw;
            }
        }
        public bool Delete(tbl_NhomTC obj)
        {
            throw new NotImplementedException();
        }
    }
}
